package ATM.Service;

import ATM.dao.ATMDao;
import ATM.domain.Account;

import java.util.ArrayList;

public class ATMService {
    public boolean createAccount(Account account) {
        ATMDao atmDao = new ATMDao();
        boolean flag = atmDao.createAccount(account);
        return flag;
    }

    public Account findAccountByCardId(String cardId) {
        ATMDao atmDao = new ATMDao();
        ArrayList<Account> list = atmDao.giveList();
        if(list.size() == 0){
            return  null;
        }
        for (int i = 0; i < list.size(); i++) {
            Account account = list.get(i);
            if(cardId.equals(account.getCardId())){
                    return account;
            }
        }
        return null;
    }

    public boolean deleteAccount(Account loginAcc) {
        ATMDao atmDao = new ATMDao();
        boolean flag = atmDao.deleteAccount(loginAcc);
        return flag;
    }

    public int AccountNum() {
        ATMDao atmDao = new ATMDao();
        ArrayList<Account> list = atmDao.giveList();
        return list.size();
    }
}
